var selectData = require('./selectData')();
var self;
cc.Class({
    extends: cc.Component,

    properties: {
        select_list: cc.ScrollView,
        selectItem: cc.Prefab,
        tip_layer: cc.Node,

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        self = this;
        this.node.on('select_tip', this.backfun);
        this.select_pool = new cc.NodePool();
        this.selectItemArr = [];
        this.content = this.select_list.content;

        var fun=function(){};
        cc.find("loadbg").getComponent("loadbg").show(fun)
    },


    onEnable() {
        if (this.selectItemArr.length > 0) {
            for (var a = 0; a < this.selectItemArr.length; a++) {
                this.select_pool.put(this.selectItemArr[a]);
                this.selectItemArr.splice(a, 1);
                a--;
            }
        }
        this.select_List();
    },

    select_List() {
        let data = this.get_data();
        for (var a = 0; a < data.length; a++) {
            var item;
            if (this.select_pool.size() > 0) {
                item = this.select_pool.get();
            } else {
                item = cc.instantiate(this.selectItem);
            }
            this.selectItemArr.push(item);
            item.getComponent('select_item').init(data[a], a);
            this.content.addChild(item);
        }
    },
    /** 获取数据
    * time 2019/9/2
    * author:zzw
    * dsc:
    */

    get_data() {
        let _data = selectData.select_data;
        return _data;
    },
    /** 监听点击提示按钮
    * time 2019/9/2
    * author:zzw
    * dsc:
    */
    backfun(event) {
        if (!self.tip_layer.active) {
            let _tipdata = selectData.tipData[event.detail.id];
            self.tip_layer.getComponent("select_tip").init(_tipdata);
            self.tip_layer.active = true;

        }
    },

    backHome(evt) {
        cc.director.loadScene("game_start");
    },
    onDestroy(){
        this.node.off('select_tip', this.backfun);
    },

    // update (dt) {},
});
